package com.sian.datasource;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;

/**
 *@see 自定义 Statement
 *@author desert
 *@version 1.0
 */
public class C1Statement implements Statement{
	
	protected Statement passthru;
    protected C1Connection connection;
    protected C1Factory factory;
    
    public C1Statement(C1Factory factory, Statement statement, C1Connection conn) {
		    this.factory = factory;
	        this.passthru = statement;
	        this.connection = conn;
	    }

	
	public void addBatch(String sql) throws SQLException {
		// TODO Auto-generated method stub
		C1WriteLog.WriteLog(this.getClass().toString(), sql);
		
		this.passthru.addBatch(sql);
	}

	
	public void cancel() throws SQLException {
		// TODO Auto-generated method stub
	   this.passthru.cancel();
	}

	
	public void clearBatch() throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.clearBatch();
	}

	
	public void clearWarnings() throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.clearWarnings();
	}

	
	public void close() throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.close();
	}

	
	public boolean execute(String sql) throws SQLException {
		// TODO Auto-generated method stub
		C1WriteLog.WriteLog(this.getClass().toString(), sql);
		return this.passthru.execute(sql);
	}

	
	public boolean execute(String sql, int autoGeneratedKeys)
			throws SQLException {
		// TODO Auto-generated method stub
		C1WriteLog.WriteLog(this.getClass().toString(), sql);
		return this.passthru.execute(sql, autoGeneratedKeys);
	}

	
	public boolean execute(String sql, int[] columnIndexes) throws SQLException {
		// TODO Auto-generated method stub
		C1WriteLog.WriteLog(this.getClass().toString(), sql);
		return this.passthru.execute(sql, columnIndexes);
	}

	
	public boolean execute(String sql, String[] columnNames)
			throws SQLException {
		// TODO Auto-generated method stub
		C1WriteLog.WriteLog(this.getClass().toString(), sql);
		return this.passthru.execute(sql, columnNames);
	}

	
	public int[] executeBatch() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.executeBatch();
	}

	
	public ResultSet executeQuery(String sql) throws SQLException {
		// TODO Auto-generated method stub
		C1WriteLog.WriteLog(this.getClass().toString(), sql);
		return (factory.getResultSet(passthru.executeQuery(sql), this, "", sql));
	}

	
	public int executeUpdate(String sql) throws SQLException {
		// TODO Auto-generated method stub
		C1WriteLog.WriteLog(this.getClass().toString(), sql);
		return this.passthru.executeUpdate(sql);
	}

	
	public int executeUpdate(String sql, int autoGeneratedKeys)
			throws SQLException {
		// TODO Auto-generated method stub
		C1WriteLog.WriteLog(this.getClass().toString(), sql);
		return this.passthru.executeUpdate(sql, autoGeneratedKeys);
	}

	
	public int executeUpdate(String sql, int[] columnIndexes)
			throws SQLException {
		// TODO Auto-generated method stub
		C1WriteLog.WriteLog(this.getClass().toString(), sql);
		return this.passthru.executeUpdate(sql, columnIndexes);
	}

	
	public int executeUpdate(String sql, String[] columnNames)
			throws SQLException {
		// TODO Auto-generated method stub
		C1WriteLog.WriteLog(this.getClass().toString(), sql);
		return this.passthru.executeUpdate(sql, columnNames);
	}

	
	public Connection getConnection() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getConnection();
	}

	
	public int getFetchDirection() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getFetchDirection();
	}

	
	public int getFetchSize() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getFetchSize();
	}

	
	public ResultSet getGeneratedKeys() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getGeneratedKeys();
	}

	
	public int getMaxFieldSize() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getMaxFieldSize();
	}

	
	public int getMaxRows() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getMaxRows();
	}

	
	public boolean getMoreResults() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getMoreResults();
	}

	
	public boolean getMoreResults(int current) throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getMoreResults(current);
	}

	
	public int getQueryTimeout() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getQueryTimeout();
	}

	
	public ResultSet getResultSet() throws SQLException {
		ResultSet rs = passthru.getResultSet();
        return (rs == null)  ? null : factory.getResultSet(rs, this, "", "");
	}

	
	public int getResultSetConcurrency() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getResultSetConcurrency();
	}

	
	public int getResultSetHoldability() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getResultSetHoldability();
	}

	
	public int getResultSetType() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getResultSetType();
	}

	
	public int getUpdateCount() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getUpdateCount();
	}

	
	public SQLWarning getWarnings() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getWarnings();
	}

	
	public boolean isClosed() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.isClosed();
	}

	
	public boolean isPoolable() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.isPoolable();
	}

	
	public void setCursorName(String name) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setCursorName(name);
	}

	
	public void setEscapeProcessing(boolean enable) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setEscapeProcessing(enable);
	}

	
	public void setFetchDirection(int direction) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setFetchDirection(direction);
	}

	
	public void setFetchSize(int rows) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setFetchSize(rows);
	}

	
	public void setMaxFieldSize(int max) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setMaxFieldSize(max);
	}

	
	public void setMaxRows(int max) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setMaxRows(max);
	}

	
	public void setPoolable(boolean poolable) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setPoolable(poolable);
	}

	
	public void setQueryTimeout(int seconds) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setQueryTimeout(seconds);
	}

	
	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.isWrapperFor(iface);
	}

	
	public <T> T unwrap(Class<T> iface) throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.unwrap(iface);
	}


	public void closeOnCompletion() throws SQLException {
		// TODO Auto-generated method stub
		
	}


	public boolean isCloseOnCompletion() throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

}
